/**
 * CS307 Team 11 Spring 2011
 * @author Kevin Barlow
 * @author David Barnes
 * @author Max Cohen
 * @author Yoongu Kang
 * @author Matt Lathrop
 * @author Thomas Maley
 * 
 * Reminders belong to NormalEvents.  They invoke the actual functionality of 
 * sending out an email or SMS to Volunteers.  Reminders store the message that
 * will be sent to the Volunteers; beyond this, a Reminder stores access to its 
 * parent Event, so that it can determine a list of Volunteers that will receive 
 * the message, and it stores the time at which the message needs to be sent.  
 * It also stores a list of recipients, in the form of a list of Volunteers and a 
 * list of Groups, just like an Event.  By default, it simply inherits these lists 
 * from its Event, but they can be modified by Administrators so that the admins 
 * can decide to include or exclude certain people from a certain Reminder for an Event.
 * 
 * 
 */


package com.cs307.redcross.client;

import java.io.Serializable;
import java.util.Date;
import java.util.Vector;

//import com.cs307.redcross.server.Mail;


public class Reminder /*extends Event*/ implements Serializable /*, ReminderService */ {

	/**
	 * 
	 */
	private static final long serialVersionUID = 5996256545813471330L;
	
	
	
	private Date timeOfReminder; 
	protected String message;
	protected Vector<Person> people; //Stores the list of recipients for the reminder
	protected Vector<Group> groups;
	protected boolean email;
	protected boolean SMS;
	private Event event; //Event that this is a reminder for
	private int id;
	private boolean sent;

	
	/**
	 * creates a generic Reminder
	 */
	public Reminder(){
		this(null, null, null, null, "");
	}
	
	/**
	 * Creates a mew Reminder
	 * 
	 * @param time the time for the reminder to go off
	 * @param mes the message the reminder will send
	 * @param rec the people that the reminder needs to be sent to
	 * TODO: pick a type for rec
	 * 
	 */
	
	public Reminder(Event eID, Date time, Vector<Group> gr, Vector<Person> pe, String mes){
		this.id=-1;
		this.event = eID;
		this.setTime(time);
		this.setMessage(mes);
		this.setPeople(pe);
		this.setGroups(gr);
		this.email = false;
		this.SMS = false;
		sent = false;
	}
	
	public Reminder(Event eID, Date time, Vector<Group> gr, Vector<Person> pe, String mes, int deliveryMethod){
		this.id=-1;
		this.event = eID;
		this.setTime(time);
		this.setMessage(mes);
		this.setPeople(pe);
		this.setGroups(gr);
		if (deliveryMethod == 0) {
			this.email = true;
			this.SMS = true;
		}
		else if (deliveryMethod == 1) {
			this.email = true;
			this.SMS = false;
		}
		else {
			this.email = false;
			this.SMS = true;
		}
		sent = false;
	}
	
/*	public Reminder(ReminderTemplate r, Event e) //We decided not to use this constructor
	{
		this.id = -1;
		this.event = e;
		this.message = r.getMessage();
		this.people = r.getPeople();
		this.groups = r.getGroups();
		this.email = r.email;
		this.SMS = r.SMS;
		this.sent = false;
		this.timeOfReminder = new Date(e.startTime.getTime()-r.getTimeBeforeEvent()*60*1000);
		//TODO: make this work
		
	}*/
	
	public Date getTimeOfReminderFromTemplate(ReminderTemplate r, Event e)
	{
		return new Date(e.startTime.getTime()-r.getTimeBeforeEvent()*60*1000);
	}
	
	@Override
	public String toString() {
		return "Reminder [timeOfReminder=" + timeOfReminder + ", message="
				+ message + ", people=" + people + ", groups=" + groups
				+ ", event=" + event + ", id=" + id + ", sent=" + sent + "]";
	}

	/**
	 * Sets the current reminder time
	 * @param time of the reminder
	 * 
	 */
	
	public void setReminder( Date time ){
		
		this.setTime(time);
		
	}
	
	/**
	 * Sends the reminder the the list of recipients
	 * @return whether the send reminder failed or not
	 */
	
/*	public boolean sendReminder(){
		//might just send the message to people after added to the tpeople Vector
		Vector<Person> tpeople = new Vector<Person>();
		
		for ( Person p : people ){
			tpeople.add( p );

		}
		for( Group g : groups ){
			Vector<Person> pe = g.getPersonList();
			for( Person p : pe ){
				if ( tpeople.indexOf( p ) < 0 ){
					//not found in Vector
					tpeople.add( p );
				}
			}
		}
		sent = true;
		//Mail.sendeMail(tpeople, message, event.getName() );
		//TODO: find a way to only send rounds of 100 at a time then sleep for 10 seconds or so
		//return Mail.sendSMS( tpeople, messag, event.getName() );
		return false;
	}*/
	
	/**
	 * Creates the reminders for the current event
	 * 
	 * @return if the reminder got added to the list
	 */
	
	public boolean createReminders(){
		//TODO: create a reminder for the event and adds it to the list of reminders in the calendar
		
		return true;
		
	}
	
	public int getID()
	{
		return id;
	}

	public void setTime(Date time) {
		this.timeOfReminder = time;
	}

	public Date getTime() {
		return timeOfReminder;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public String getMessage() {
		return message;
	}

	public void setPeople(Vector<Person> people) {
		this.people = people;
	}

	public Vector<Person> getPeople() {
		return people;
	}

	public void setGroups(Vector<Group> groups) {
		this.groups = groups;
	}

	public Vector<Group> getGroups() {
		return groups;
	}

	public void setEvent(Event event) {
		this.event = event;
	}

	public boolean isEmail() {
		return email;
	}

	public void setEmail(boolean email) {
		this.email = email;
	}

	public boolean isSMS() {
		return SMS;
	}

	public void setSMS(boolean sMS) {
		SMS = sMS;
	}

	public Event getEvent() {
		return event;
	}
	public static void main( String[] args ){
		//Vector<Group> g = new Vector<Group>();
		Vector<Person> p = new Vector<Person>();
		//public Volunteer(int i, String firstName, String lastName, String email, String carrier, String cellPhoneNumber, String smsEmail, String username, String password, Vector<FreeTimeEvent> freeTimeEvents) {
		Person pe = new Volunteer("David", "Barnes", "dvbarnes@purdue.edu", "at&t", "6309135510", "6309135510@txt.att.net", "dvbarnes", "password", new Vector<FreeTimeEvent>() );
		//for( int i=0;i< 99; i++ ){
		p.add ( pe );
		//}
		
	//	Reminder r = new Reminder( 1, new Event(), new Date(), g, p, "hello" );
		//r.sendReminder();
		//*/
	}

	public void setSent(boolean sent) {
		this.sent = sent;
	}

	public boolean isSent() {
		return sent;
	}
	public void setId(int id) {
		this.id = id;
	}
}
